package config;


import data.dao.MyJdbcQuery;
import data.entity.User_Entity;
import data.vo.Privilege;
import data.vo.SampleUserDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.List;

/**
 * @author niwb
 * @version 2016-10-18 下午2:34:44
 * 
 */
public class ZuulUserDetailService implements UserDetailsService {

	@Autowired
	private MyJdbcQuery jdbcQuery;

	@Override
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException {
		User_Entity user = jdbcQuery.getUser4Auth(userName);
		List<Privilege> privileges = jdbcQuery.getUserPrivilege(user.getId());
		SampleUserDetail userDetail = new SampleUserDetail(user,privileges);
		return userDetail;
	}

}
